home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / lib / c / stdlib / atexit.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-03-27  |  2.0 KB  |  67 lines

  1. /* 
  2.  * atexit.c --
  3.  *
  4.  *    This file contains the source code for the "atexit" library
  5.  *    procedure.
  6.  *
  7.  * Copyright 1988 Regents of the University of California
  8.  * Permission to use, copy, modify, and distribute this
  9.  * software and its documentation for any purpose and without
  10.  * fee is hereby granted, provided that the above copyright
  11.  * notice appear in all copies.  The University of California
  12.  * makes no representations about the suitability of this
  13.  * software for any purpose.  It is provided "as is" without
  14.  * express or implied warranty.
  15.  */
  16.  
  17. #ifndef lint
  18. static char rcsid[] = "$Header: /sprite/src/lib/c/stdlib/RCS/atexit.c,v 1.5 92/03/27 13:41:19 rab Exp $ SPRITE (Berkeley)";
  19. #endif /* not lint */
  20.  
  21. #include <stdlib.h>
  22.  
  23. /*
  24.  * Variables shared with exit.c:
  25.  */
  26.  
  27. extern void (*_exitHandlers[])();    /* Function table. */
  28. extern int _exitNumHandlers;        /* Number of functions currently
  29.                      * registered in table. */
  30. extern long _exitHandlerArgs[];        /* Arguments to pass to functions. */
  31. extern int _exitTableSize;        /* Number of entries in table. */
  32.  
  33. /*
  34.  *----------------------------------------------------------------------
  35.  *
  36.  * atexit --
  37.  *
  38.  *    Register a function ("func") to be called as part of process
  39.  *    exiting.
  40.  *
  41.  * Results:
  42.  *    The return value is 0 if the registration was successful,
  43.  *    and -1 if registration failed because the table was full.
  44.  *
  45.  * Side effects:
  46.  *    Information will be remembered so that when the process exits
  47.  *    (by calling the "exit" procedure), func will be called.  Func
  48.  *    takes no arguments and returns no result.  If the process
  49.  *    terminates in some way other than by calling exit, then func
  50.  *    will not be invoked.
  51.  *
  52.  *----------------------------------------------------------------------
  53.  */
  54.  
  55. int
  56. atexit(func)
  57.     void (*func)();            /* Function to call during exit. */
  58. {
  59.     if (_exitNumHandlers >= _exitTableSize) {
  60.     return -1;
  61.     }
  62.     _exitHandlers[_exitNumHandlers] = func;
  63.     _exitHandlerArgs[_exitNumHandlers] = 0;
  64.     _exitNumHandlers += 1;
  65.     return 0;
  66. }
  67.